<template>
  <div class="venus-list-page">
    <!--自定义资产类别信息查询界面-->
    <div class="page-search">
      <el-row type="flex" class="search-list">
        <el-row type="flex" class="list-items">
          <div class="venus-input-box">
            <label>资产类别名称</label>
            <el-input
              v-model="table.assdept_type_table.ad_name"
              class="venus-input-middle"
              placeholder="请输入资产类别名称"
            />
          </div>
          <div class="venus-input-box">
            <label>模板名称</label>
            <el-select
              v-model="table.assdept_type_table.mod_id"
              class="venus-input-middle"
              placeholder="--请选择模板名称--"
            >
              <el-option
                v-for="(item) in dict.modIdItems"
                :key="item.value"
                :label="item.text"
                :value="item.value"
              />
            </el-select>
          </div>
        </el-row>
        <div class="venus-btn-box">
          <el-button type="primary" @click="search">查询</el-button>
          <el-button type="primary" @click="reSet">重置</el-button>
          <el-button type="primary" @click="addBean">新增</el-button>
        </div>
      </el-row>
    </div>
    <!--    查询列表返显-->
    <div class="page-list">
      <el-row type="flex" justify="space-between" class="page-list-head">
        <div class="title">查询结果</div>
      </el-row>
      <table-pagination
        :dict-data="dict"
        :table-data="table.assdept_type_table.tableData"
        :table-header-config="table.tableHeaderConfig"
        highlight-current-row
        :total="table.assdept_type_table.total"
        :page-size="table.assdept_type_table.limit"
        :now-page="table.assdept_type_table.nowPage"
        @current-change="currentChange"
        :operation-config="table.operationConfig"
      />
    </div>
    <el-dialog :title="dialog.assdeptType.title" :visible.sync="dialog.assdeptType.formVisible">
      <!-- ref=dlgForm用于验证表单 -->
      <el-form ref="assdeptTypelog" :model="dialog.form" size="mini">
        <el-row>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产类别"
              :label-width="dialog.formLabelWidth"
              prop="ad_name"
              :rules="dialog.formRules.ad_name"
            >
              <el-input v-model="dialog.form.ad_name"
                        :disabled="dialog.assdeptType.dlgFormDisabled"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="模板名称"
              :label-width="dialog.formLabelWidth"
              prop="t8_assdept_mod_id"
              :rules="dialog.formRules.t8_assdept_mod_id"
            >
              <el-select
                v-model="dialog.form.t8_assdept_mod_id"
                placeholder="请选择模板名称"
                filterable
                clearable
                :disabled="dialog.assdeptType.dlgFormDisabled"
              >
                <el-option
                  v-for="(item) in dict.modIdItems"
                  :key="item.value"
                  :label="item.value+'-'+item.text"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="核算类型"
              :label-width="dialog.formLabelWidth"
              prop="calc_type"
            >
              <el-select
                v-model="dialog.form.calc_type"
                placeholder="请选择核算类型"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.calc_type"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="科目分类"
              :label-width="dialog.formLabelWidth"
              prop="subj_type"
            >
              <el-select
                v-model="dialog.form.subj_type"
                placeholder="请选择科目分类"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.subj_type"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="会计分类"
              :label-width="dialog.formLabelWidth"
              prop="account_type"
            >
              <el-select
                v-model="dialog.form.account_type"
                placeholder="请选择会计分类"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.account_type"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产类型"
              :label-width="dialog.formLabelWidth"
              prop="adtype_type"
              v-show = 'dialog.showAdtype_type'
            >
              <el-select
                v-model="dialog.form.adtype_type"
                placeholder="请选择资产类型"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.adtype_type"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="是否需要投后管理"
              :label-width="dialog.formLabelWidth"
              prop="is_ctrl_end"
            >
              <el-select
                v-model="dialog.form.is_ctrl_end"
                placeholder="请选择是否需要投后管理"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.is_ctrl_end"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产一级分类"
              :label-width="dialog.formLabelWidth"
              prop="cbc_type"
            >
              <el-select
                v-model="dialog.form.cbc_type"
                placeholder="请选择资产一级分类"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.cbc_type"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产二级分类"
              :label-width="dialog.formLabelWidth"
              prop="cbc_subtype"
            >
              <el-select
                v-model="dialog.form.cbc_subtype"
                placeholder="请选择资产二级分类"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.cbc_subtype"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="投资比例类型"
              :label-width="dialog.formLabelWidth"
              prop="investment_code"
            >
              <el-select
                v-model="dialog.form.investment_code"
                placeholder="请选择投资比例类型"
                filterable
                clearable
              >
                <el-option
                  v-for="(value,key) in dict.investment_code"
                  :key="key"
                  :label="value"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产分类"
              :label-width="dialog.formLabelWidth"
              prop="adtype_class"
              :rules="dialog.formRules.adtype_class"
            >
              <el-select
                v-model="dialog.form.adtype_class"
                placeholder="请选择资产分类"
                @change="adtype_change"
              >
                <el-option
                  v-for="(text,key) in dict.adtype_class"
                  :key="key"
                  :label="text"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="是否非标"
              :label-width="dialog.formLabelWidth"
              prop="is_unstd"
              :rules="dialog.formRules.is_unstd"
            >
              <el-select
                v-model="dialog.form.is_unstd"
                placeholder="请选择是否非标"
              >
                <el-option
                  v-for="(text,key) in dict.is_unstd"
                  :key="key"
                  :label="text"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :sm="12" :md="12">
            <el-form-item
              label="资产投资性质"
              :label-width="dialog.formLabelWidth"
              prop="invest_prop_type"
              :rules="dialog.formRules.invest_prop_type"
            >
              <el-select
                v-model="dialog.form.invest_prop_type"
                placeholder="请选择资产投资性质"
              >
                <el-option
                  v-for="(text,key) in dict.invest_prop_type"
                  :key="key"
                  :label="text"
                  :value="key"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align: center">
        <el-button type="success" @click="dialog.assdeptType.commit">确 定</el-button>
        <el-button type="info" plain @click="dialog.assdeptType.formVisible=false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import request from "../../../../../utils/request";
  import * as kk from "../../../../../utils/k-utils";

  export default {
    name: 'M82002',
    data() { // 数据定义
      return {
        dict: {
          modIdItems: {}, //模板名称
          calc_type: {}, //核算类型
          subj_type: {}, //科目分类
          account_type: {}, //会计分类
          adtype_type: {}, //资产类型
          is_ctrl_end: {}, //是否需要投后管理
          cbc_type: {}, //资产一级分类
          cbc_subtype: {}, //资产二级分类
          investment_code: {}, //投资比例类型
          adtype_class: {}, //资产分类
          invest_prop_type: {}, //资产投资性质
          is_unstd: {}, //是否非标
        },
        table: {
          tableHeaderConfig: [ // 表头配置
            {prop: 'ad_name', label: '资产类别名称'},
            {prop: 'mod_name', label: '模板名称'},
            {prop: 'adtype_class', label: '资产分类'},
            {prop: 'calc_type', label: '核算类型'},
            {prop: 'subj_type', label: '科目分类'},
            {prop: 'invest_prop_type', label: '资产投资性质'}
          ],
          operationConfig: { // 表格操作配置
            fixed: 'right',
            width: 200,
            operationButton: [
              // 每一个操作。value:操作文字；func:回调函数
              {value: '修改', func: this.myModify},
              {value: '删除', func: this.myDelete}
            ]
          },
          assdept_type_table: {
            total: 0,
            nowPage: 1,
            limit: 5,
            tableData: [], // 表格数据
            exeid: 'M8204S001',//exeid
            ad_name: '', // 资产类别名称
            mod_id: '', // 资产类别名称
          }
        },
        dialog: {
          formLabelWidth: '100px',
          showAdtype_type: false,
          formRules: {
            ad_name: [
              {required: true, message: '请输入资产类别', trigger: 'blur'}
            ],
            t8_assdept_mod_id: [
              {required: true, message: '请选择模板名称', trigger: 'change'}
            ],
            adtype_class: [
              {required: true, message: '请选择资产分类', trigger: 'change'}
            ],
            is_unstd: [
              {required: true, message: '请选择是否非标', trigger: 'change'}
            ],
            invest_prop_type: [
              {required: true, message: '请选择资产投资性质', trigger: 'change'}
            ],
          },
          form: {
            ad_name: '', // 资产类别
            t8_assdept_mod_id: '', // 模板名称
            calc_type: '', // 核算类型
            subj_type: '', // 科目分类
            account_type: '', // 会计分类
            adtype_type: '', // 资产类型
            adtype_class: '', // 资产分类
            is_ctrl_end: '', // 是否需要投后管理
            cbc_type: '', // 资产一级分类
            cbc_subtype: '', // 资产二级分类
            investment_code: '', // 投资比例类型
            is_unstd: '', // 是否非标
            invest_prop_type: '', // 是否非标
          },
          assdeptType: {
            title: '',
            dlgFormDisabled: false,
            formVisible: false,
            commit: ''
          }
        },
      }
    },
    mounted() {
      // 初始化调用
      this.init()
    },
    methods: {
      // 页面初始化
      init: function () {
        this.load_dict_exeid(this, 'custom', 'M8000ADTYPE', 'modIdItems')
        kk.k_load_dict(this, 'adtype_class', 't8_adtype_class');
        kk.k_load_dict(this, 'calc_type', 't8_cust_calc_type');
        kk.k_load_dict(this, 'subj_type', 't8_cust_subj_type');
        kk.k_load_dict(this, 'account_type', 't8_account_type_self');
        kk.k_load_dict(this, 'adtype_type', 't8_adtype_type');
        kk.k_load_dict(this, 'is_ctrl_end', 't8_1yes0no');
        kk.k_load_dict(this, 'invest_prop_type', 't8_invest_prop_type2');
        kk.k_load_dict(this, 'is_unstd', 't8_1yes0no');
        kk.k_load_dict(this, 'cbc_type', 't8_chinabond_type');
        kk.k_load_dict(this, 'cbc_subtype', 't8_cbc_subtype');
        kk.k_load_dict(this, 'investment_code', 't8_investment_type');
        this.table.assdept_type_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'assdept_type_table', 'custom');
      },
      // 事件触发
      search() { // 查询函数
        this.table.assdept_type_table.nowPage = 1 // 初始第一页
        kk.k_load_table(this, 'assdept_type_table', 'custom')
      },
      reSet() {//重置
        this.table.assdept_type_table.ad_name = ''
        this.table.assdept_type_table.mod_id = ''
      },
      // ======================表格======================
      addBean() {
        this.resetObj(this.dialog.form)
        this.dialog.assdeptType.commit = this.addCommit
        this.dialog.assdeptType.title = '新增资产负债类别'
        this.dialog.assdeptType.dlgFormDisabled = false
        this.dialog.assdeptType.formVisible = true
      },
      myModify(item, index) {
        this.copyObj(item, this.dialog.form)
        this.dialog.assdeptType.commit = this.modifyCommit
        this.dialog.assdeptType.title = '修改资产负债类别'
        this.dialog.assdeptType.dlgFormDisabled = true
        this.dialog.assdeptType.formVisible = true
      },
      addCommit() {
        // 获取全局对象数据
        var bean = this.dialog.form
        var _this = this
        this.send_save('custom', 'M8204ADD001', bean).then(rep => {
          _this.search()
          // 关闭弹出框
          _this.dialog.assdeptType.formVisible = false
        })
      },
      modifyCommit() {
        // 获取全局对象数据
        var bean = this.dialog.form
        var _this = this
        this.send_save('custom', 'M8204UP001', bean).then(rep => {
          _this.search()
          // 关闭弹出框
          _this.dialog.assdeptType.formVisible = false
        })
      },
      copyObj(obj1, obj2) {
        for (var key in obj1) {
          // 原型对象不拷贝
          if (key === '__proto__') {
            continue
          }
          // 不存在的属性不拷贝
          if (!obj2.hasOwnProperty(key)) {
            continue
          }
          // 自动将number转换成string
          if (typeof obj1[key] === 'number') {
            obj1[key] = '' + obj1[key]
          }
          obj2[key] = obj1[key]
        }
      },
      resetObj(obj) {
        for (var key in obj) {
          obj[key] = ''
        }
      },
      myDelete(item, index) {

      },
      // 发送保存
      send_save(service_name, exeid, params) {
        params.exeid = exeid
        return request({
          loading: true,
          url: service_name + '/base/comn-update.json',
          method: 'post',
          params: params
        })
      },
      // 是否资管计划
      adtype_change(item, index) {
        if (item == 3) {
          this.dialog.showAdtype_type = true
        }else {
          this.dialog.showAdtype_type = false
        }
      },
      //下一页
      currentChange(index) {
        this.table.assdept_type_table.nowPage = index;
        kk.k_load_table(this, 'assdept_type_table', 'custom');
      },
      /* 通过exeid加载字典 */
      load_dict_exeid(this_object, service_name, exeid, dict) {
        request({
          loading: true,
          url: service_name + '/base/comn-query.json?exeid=' + exeid,
          method: 'post'
        }).then(rep => {
          console.log(rep)
          this_object['dict'][dict] = rep.rows
        })
      },
    }
  }
</script>

<style scoped>
</style>
